## Replication of
## Table 1: Randomization Check for Label Experiment
## Table 2: Randomization Check for Price Experiment
rm(list=ls())
library(Matching)
library(foreign)
library(ebal)

d <- read.dta("repTable1and2.dta")
set.seed(1234)

## Table 1: Randomization Check for Label Experiment
covarsexp1 <- colnames(d)[c(4:15,26:40)]
out.b <- MatchBalance(d$exp1_treat~as.matrix(d[,covarsexp1]),
                      match.out=NULL,nboots=1000)
bal.b <- baltest.collect(matchbal.out=out.b,
                         var.names=covarsexp1,after=FALSE)
tab1 <- round(bal.b[,c(1,2,6,7)],2)

coffees <- c("Avg. Sales FR Regular Bulk ($)",
               "Avg. Sales Coffee Blend Bulk ($)",
               "Avg. Sales All Bulk Coffees ($)",
               "Avg. Sales All Instant Coffees ($)",
               "Avg. Sales All Packaged Coffees ($)")

rownames(tab1)  <-
  c("Total Store Sales 2008 ($)",
   "Total Store Sales Growth 2008-2009 (%)",
  paste(coffees,
   c("4 Weeks"),sep="-"),
  paste(coffees,
   c("52 Weeks"),sep="-"),
  "Total Population",
  "African American Pop (%)",
  "Foreign Born Pop (%)",
  "Median HH Income ($)",
  "HHs with Soc. Security Income (%)",
  "Public Assistance per capita ($)",
  "Family HHs (%)",
  "HH Head Aged 15-34 (%)",
  "HH Head Aged 65+ (%)",
  "In High School (%)",
  "In College (%)",
  "High School Dropouts (%)",
  "High School Graduates (%)",
  "BA Degree (%)",
  "Graduate Degree (%)")

tab1

## Table 2: Randomization Check for Price Experiment
covarsexp2 <- colnames(d)[c(4:5,16:40)]
## fill up one missing value to avoid listwise deletion
d$exp2_CBB4[is.na(d$exp2_CBB4)] <- 0
out.b <- MatchBalance(d$exp2_treat~as.matrix(d[,covarsexp2]),
                      match.out=NULL,nboots=1000)
bal.b <- baltest.collect(matchbal.out=out.b,
                         var.names=covarsexp2,after=FALSE)
tab2 <- round(bal.b[,c(1,2,6,7)],2)

# rerun for var with missing values
d <- read.dta("repTable1and2.dta")
out.b <- MatchBalance(d$exp2_treat~d$exp2_CBB4,
                      match.out=NULL,nboots=1000)
bal.b <- baltest.collect(matchbal.out=out.b,
                         var.names="exp2_CBB4",after=FALSE)
tab2sub <- round(bal.b[1,c(1,2,6,7)],2)
# replace
tab2[rownames(tab2)=="exp2_CBB4",] <- tab2sub

rownames(tab2)  <-
  c("Total Store Sales 2008 ($)",
    "Total Store Sales Growth 2008-2009 (%)",
    paste(coffees,
          c("4 Weeks"),sep="-"),
    paste(coffees,
          c("52 Weeks"),sep="-"),
    "Total Population",
    "African American Pop (%)",
    "Foreign Born Pop (%)",
    "Median HH Income ($)",
    "HHs with Soc. Security Income (%)",
    "Public Assistance per capita ($)",
    "Family HHs (%)",
    "HH Head Aged 15-34 (%)",
    "HH Head Aged 65+ (%)",
    "In High School (%)",
    "In College (%)",
    "High School Dropouts (%)",
    "High School Graduates (%)",
    "BA Degree (%)",
    "Graduate Degree (%)")

tab2

